import Vue from 'vue';

const basicsList = require.context('./basics', true, /.vue$/); //获取基础素材文件
const complexList = require.context('./complex', true, /.vue$/); //获取高级素材文件
const technicalList = require.context('./technical', true, /.vue$/); //获取工业素材文件

const GetBasicsList = () => {
	let list = [];
	basicsList.keys().forEach(fileName => {
		const component = basicsList(fileName).default; // 基础组件
		const componentName = component.pageData.name;
		const hidden = component.pageData.hidden;
		if (componentName) Vue.component(componentName, component);
		if (!hidden) list.push(component.pageData);
	});

	list = list.sort(function(a, b) {
		return a.sort - b.sort;
	});
	return list;
};


const GetComplexList = () => {
	let list = [];
	complexList.keys().forEach(fileName => {
		const component = complexList(fileName).default; // 高级组件
		const componentName = component.pageData.name;
		if (componentName) Vue.component(componentName, component);
		list.push(component.pageData);
	});

	list = list.sort(function(a, b) {
		return a.sort - b.sort;
	});
	return list;
};

const GetTechnicalListList = () => {
	let list = [];
	technicalList.keys().forEach(fileName => {
		const component = technicalList(fileName).default; // 高级组件
		const componentName = component.pageData.name;
		if (componentName) Vue.component(componentName, component);
		list.push(component.pageData);
	});

	list = list.sort(function(a, b) {
		return a.sort - b.sort;
	});
	return list;
};

const ComplexList = () => {
	let list = [{
		title: '基础组件',
		name: 'basics',
		show: true,
		complex: GetBasicsList()
	}, {
		title: '高级组件',
		name: 'basics',
		show: true,
		complex: GetComplexList()
	}, {
		title: '工业组件',
		name: 'technical',
		show: true,
		complex: GetTechnicalListList()
	}]
	return list;
}

export default ComplexList;
